﻿using CPPEI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XWeb.Core.Services
{
    public class UpdateService
    {
        public ServiceResult UpdateApp(string name, string icon)
        {
            using (XWebDbContext dbContext = new XWebDbContext())
            {
                EntityRepository<Entities.App> rep = new EntityRepository<Entities.App>(dbContext);

                Entities.App app = rep.Query().SingleOrDefault();
                if (app == null)
                {
                    return new ServiceResult(Error.COM_ObjNotExist);
                }

                app.Name = name;
                app.Icon = icon;
                app.CreatedTime = DateTime.Now;
                rep.Update(app);

                try
                {
                    dbContext.SaveChanges();
                    return new ServiceResult();
                }
                catch(Exception ex)
                {
                    return new ServiceResult(Error.COM_Exception, ex.Message);
                }
            }
        }
    }
}
